<script type='text/javascript' language='javascript'>
function changeState(v,r,t){
	var id = v.value;
    $.ajax({
            url: '{base_url}customer/province/'+id+'/'+t,
            type:'POST',
            dataType: 'json',
            success: function(output_string){
                document.getElementById(r).innerHTML = output_string;
            }, // End of success function of ajax form
         
    }); // End of ajax call 

}
$.fn.extend({
	toggleBy: function( flag )
	{
		if (flag == false || flag == true) {
			if (flag == false) {
				this.show();
			} else {
				this.hide();
			}
		} else {
			this.toggle();
		}

		return true;
	},

	

	// Disables/enables all children inside selected element according to visibility
	toggleElements: function()
	{
		var self = $(this);
		$(':input', this).attr('disabled', (self.css('display') == 'none') ? true : false);
	},

	// Override default jQuery click method with more smart and working :)
	click: function(fn)
	{
		if (fn)	{
			return this.bind('click', fn);
		}

		$(this).each(function() {
			if (document.createEventObject) {
				$(this).trigger('click');
			} else {
				var evt_obj = document.createEvent('MouseEvents');
				evt_obj.initEvent('click', true, true);
				this.dispatchEvent(evt_obj);
			}
		});
	},

	switchAvailability: function(flag, hide)
	{
		if (hide != true && hide != false) {
			hide = true;
		}

		if (flag == false || flag == true) {
			if (flag == false) {
				$(':input:not(.cm-skip-avail-switch)', this).attr('disabled', '');
				$(':input:not(.cm-skip-avail-switch)', this).removeClass('disabled');
				if (hide) {
					this.show();
				}
			} else {
				$(':input:not(.cm-skip-avail-switch)', this).attr('disabled', 'disabled');
				$(':input:not(.cm-skip-avail-switch)', this).addClass('disabled');
				if (hide) {
					this.hide();
				}
			}
		} else {
			$(':input', this).each(function(){
				var self = $(this);
				self.attr('disabled', !self.attr('disabled'));
			});
			if (hide) {
				this.toggle();
			}
		}
	},


});

</script>

<div id="details">

<div class="header-active">
<ul class="clearfix">
<li>
<h3 class="uppercase"><?php echo lang('edit_contact');?></h3>
</li>                             
</ul>
</div>

<div class="form-content">
<div class="products clearfix">
<div id="error">
{error_message}
</div>
<?php if(isset($update_profile)):?>
<div class="profile_form contacts_form">
<form action="<?php echo site_url('customer/contacts');?>" method="post" name="contacts_form">
	<h2 class="subheader"><?php echo lang("billing_address");?></h2>
	<div class="main_billing_address" id= "main_billing_address" >
	<div class="form-field float-left"><label class="cm-required" for="b_contacts_firstname"><?php echo lang("firstname");?>:</label>
	<input type="text" name="contacts[b_firstname]" id="b_contacts_firstname" class="input-text" value="{b_firstname}" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_lastname"><?php echo lang("lastname");?>:</label>
	<input type="text" name="contacts[b_lastname]" id="b_contacts_lastname" class="input-text" value="{b_lastname}" />
	</div>
	<div class="clear"></div>
	<div class="form-field"><label class="cm-required" for="b_contacts_company"><?php echo lang("company");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[b_company]" id="b_contacts_company" class="input-long-text " value ="{b_company}"/>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required cm-phone" for="b_contacts_phone"><?php echo lang("phone");?>:</label>
	<input type="text" name="contacts[b_phone]" id="b_contacts_phone" class="input-text" value="{b_phone}" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_fax"><?php echo lang("fax");?>:</label>
	<input type="text" name="contacts[b_fax]" id="b_contacts_fax" class="input-text" value="{b_fax}" />
	</div>
	<div class="clear"></div>
	<div class="form-field "><label class="cm-required" for="b_contacts_address"><?php echo lang("address");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[b_address]" id="b_contacts_address" class="input-long-text" value="{b_address}" />
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="b_contacts_city"><?php echo lang("city");?>:</label>
	<input type="text" name="contacts[b_city]" id="b_contacts_city" class="input-text" value="{b_city}" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_state"><?php echo lang("state");?>:</label>
	<div id="result_b_state"><input type="text" name="contacts[b_state]" id="b_contacts_state" class="input-text" value="{b_state}"/></div>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="b_contacts_zipcode"><?php echo lang("zipcode");?>:</label>
	<input type="text" id="b_contacts_zipcode" name="contacts[b_zipcode]" class="input-text" value="{b_zipcode}" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_country"><?php echo lang("country");?>:</label>
	<select id="b_contacts_country" name="contacts[b_country]" onchange="changeState(this,'result_b_state','b')"> <!--  onchange="jQuery.ajaxRequest('<?php echo base_url();?>customer/province/'+this.value+'/b',{method: 'POST', cache: false, result_ids: 'result_b_state',data:{type:'b'}});"> -->
	{b_country_a}
	</select>
	</div>
	<div class="clear"></div>
	</div>
	<h2 class="subheader">
	<?php echo lang("shipping_address");?>
	<span class="title-extra">
		<input type="hidden" name="copy_address" value="">
		<input class="checkbox" id="elm_ship_to_another" type="checkbox" name="copy_address" value="Y" onclick="$('#sa').switchAvailability(this.checked, true);" >
		<a onclick="$('#elm_ship_to_another').click();"><?php echo lang('use_billing_address');?></a>
	</span>
	</h2>
	<div class="main_shipping_address" id="sa">
	<div class="form-field float-left"><label class="cm-required" for="s_contacts_firstname"><?php echo lang("firstname");?>:</label>
	<input type="text" name="contacts[s_firstname]" id="s_contacts_firstname" class="input-text" value="{s_firstname}" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_lastname"><?php echo lang("lastname");?>:</label>
	<input type="text" name="contacts[s_lastname]" id="s_contacts_lastname" class="input-text" value="{s_lastname}" />
	</div>
	<div class="clear"></div>
	<div class="form-field"><label class="cm-required" for="s_contacts_company"><?php echo lang("company");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[s_company]" id="s_contacts_company" class="input-long-text " value="{s_company}"/>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required cm-phone" for="s_contacts_phone"><?php echo lang("phone");?>:</label>
	<input type="text" name="contacts[s_phone]" id="s_contacts_phone" class="input-text" value="{s_phone}"/>
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_fax"><?php echo lang("fax");?>:</label>
	<input type="text" name="contacts[s_fax]" id="s_contacts_fax" class="input-text" value="{s_fax}"/>
	</div>
	<div class="clear"></div>
	<div class="form-field "><label class="cm-required" for="s_contacts_address"><?php echo lang("address");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[s_address]" id="s_contacts_address" class="input-long-text " value="{s_address}" />
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="s_contacts_city"><?php echo lang("city");?>:</label>
	<input type="text" name="contacts[s_city]" id="s_contacts_city" class="input-text" value="{s_city}" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_state"><?php echo lang("state");?>:</label>
	<div id="result_s_state"><input type="text" name="contacts[s_state]" id="s_contacts_state" class="input-text" value="{s_state}"/></div>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="s_contacts_zipcode"><?php echo lang("zipcode");?>:</label>
	<input type="text" id="s_contacts_zipcode" name="contacts[s_zipcode]" value="{s_zipcode}" class="input-text" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_country"><?php echo lang("country");?>:</label>
	<select id="s_contacts_country" name="contacts[s_country]" onchange="changeState(this,'result_s_state','s')"> <!-- onchange="jQuery.ajaxRequest('<?php echo base_url();?>customer/province/'+this.value+'/s',{method: 'POST', cache: false, result_ids: 'result_s_state',data:{type:'s'}});"> -->
	{s_country_a}
	</select>
	</div>
	<div class="clear"></div>
	</div>
	<div class="button-container">
	<button type="submit" class="button float-right" title="{lang_button_profile}" name="btnAddContacts" ><span><span>{lang_button_profile}</span></span></button>
	<div class="clear"></div>
	</div>

	
</form>
</div>
 <?php else:?>
 
 <div class="profile_form contacts_form">
<form action="<?php echo site_url('customer/contacts');?>" method="post" name="contacts_form">
	<h2 class="subheader"><?php echo lang("billing_address");?></h2>
	<div class="main_billing_address" id= "main_billing_address" >
	<div class="form-field float-left"><label class="cm-required" for="b_contacts_firstname"><?php echo lang("firstname");?>:</label>
	<input type="text" name="contacts[b_firstname]" id="b_contacts_firstname" class="input-text" value="" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_lastname"><?php echo lang("lastname");?>:</label>
	<input type="text" name="contacts[b_lastname]" id="b_contacts_lastname" class="input-text" value="" />
	</div>
	<div class="clear"></div>
	<div class="form-field"><label class="cm-required" for="b_contacts_company"><?php echo lang("company");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[b_company]" id="b_contacts_company" class="input-long-text " value =""/>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required cm-phone" for="b_contacts_phone"><?php echo lang("phone");?>:</label>
	<input type="text" name="contacts[b_phone]" id="b_contacts_phone" class="input-text" value="" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_fax"><?php echo lang("fax");?>:</label>
	<input type="text" name="contacts[b_fax]" id="b_contacts_fax" class="input-text" value="" />
	</div>
	<div class="clear"></div>
	<div class="form-field "><label class="cm-required" for="b_contacts_address"><?php echo lang("address");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[b_address]" id="b_contacts_address" class="input-long-text" value="" />
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="b_contacts_city"><?php echo lang("city");?>:</label>
	<input type="text" name="contacts[b_city]" id="b_contacts_city" class="input-text" value="" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_state"><?php echo lang("state");?>:</label>
	<div id="result_b_state"><input type="text" name="contacts[b_state]" id="b_contacts_state" class="input-text" value=""/></div>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="b_contacts_zipcode"><?php echo lang("zipcode");?>:</label>
	<input type="text" id="b_contacts_zipcode" name="contacts[b_zipcode]" class="input-text" value="" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="b_contacts_country"><?php echo lang("country");?>:</label>
	<select id="b_contacts_country" name="contacts[b_country]" onchange="changeState(this,'result_b_state','b')"> <!--  onchange="jQuery.ajaxRequest('<?php echo base_url();?>customer/province/'+this.value+'/b',{method: 'POST', cache: false, result_ids: 'result_b_state',data:{type:'b'}});"> -->
	{b_country_a}
	</select>
	</div>
	<div class="clear"></div>
	</div>
	<h2 class="subheader">
	<?php echo lang("shipping_address");?>
	<span class="title-extra">
		<input type="hidden" name="copy_address" value="">
		<input class="checkbox" id="elm_ship_to_another" type="checkbox" name="copy_address" value="Y" onclick="$('#sa').switchAvailability(this.checked, false);" >
		<a onclick="$('#elm_ship_to_another').click();"><?php echo lang('use_billing_address');?></a>
	</span>
	</h2>
	<div class="main_shipping_address" id="sa">
	<div class="form-field float-left"><label class="cm-required" for="s_contacts_firstname"><?php echo lang("firstname");?>:</label>
	<input type="text" name="contacts[s_firstname]" id="s_contacts_firstname" class="input-text" value="" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_lastname"><?php echo lang("lastname");?>:</label>
	<input type="text" name="contacts[s_lastname]" id="s_contacts_lastname" class="input-text" value="" />
	</div>
	<div class="clear"></div>
	<div class="form-field"><label class="cm-required" for="s_contacts_company"><?php echo lang("company");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[s_company]" id="s_contacts_company" class="input-long-text " value=""/>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required cm-phone" for="s_contacts_phone"><?php echo lang("phone");?>:</label>
	<input type="text" name="contacts[s_phone]" id="s_contacts_phone" class="input-text" value=""/>
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_fax"><?php echo lang("fax");?>:</label>
	<input type="text" name="contacts[s_fax]" id="s_contacts_fax" class="input-text" value=""/>
	</div>
	<div class="clear"></div>
	<div class="form-field "><label class="cm-required" for="s_contacts_address"><?php echo lang("address");?>:</label>
	<div class="clear"></div>
	<input type="text" name="contacts[s_address]" id="s_contacts_address" class="input-long-text " value="" />
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="s_contacts_city"><?php echo lang("city");?>:</label>
	<input type="text" name="contacts[s_city]" id="s_contacts_city" class="input-text" value="" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_state"><?php echo lang("state");?>:</label>
	<div id="result_s_state"><input type="text" name="contacts[s_state]" id="s_contacts_state" class="input-text" value=""/></div>
	</div>
	<div class="clear"></div>
	<div class="form-field float-left"><label class="cm-required" for="s_contacts_zipcode"><?php echo lang("zipcode");?>:</label>
	<input type="text" id="s_contacts_zipcode" name="contacts[s_zipcode]" value="" class="input-text" />
	</div>
	<div class="form-field float-right"><label class="cm-required" for="s_contacts_country"><?php echo lang("country");?>:</label>
	<select id="s_contacts_country" name="contacts[s_country]" onchange="changeState(this,'result_s_state','s')"> <!-- onchange="jQuery.ajaxRequest('<?php echo base_url();?>customer/province/'+this.value+'/s',{method: 'POST', cache: false, result_ids: 'result_s_state',data:{type:'s'}});"> -->
	{s_country_a}
	</select>
	</div>
	<div class="clear"></div>
	</div>
	<div class="button-container">
	<button type="submit" class="button float-right" title="{lang_button_profile}" name="btnAddContacts" ><span><span>{lang_button_profile}</span></span></button>
	<div class="clear"></div>
	</div>

	
</form>
</div>
 
 <?php endif;?>
 </div>
</div>
</div>